package com.sos.controller;

import com.sos.entity.po.Account;
import com.sos.entity.LayuiR;
import com.sos.entity.po.User;
import com.sos.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 港某人
 * @date 2021/3/7 13:39
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping(value = "login", method = {RequestMethod.POST})
    LayuiR<User> login(Account account) {
        User info = null;
        String login = userService.login(account);
        if (login != null) {
            info = userService.info(login);
        }
        return LayuiR.data(info);
    }

    @RequestMapping(value = "register", method = {RequestMethod.POST})
    LayuiR<String> register(@RequestBody Account account) {
        String s = userService.userRegister(account);
        return LayuiR.msg(s);
    }

    @RequestMapping(value = "info", method = {RequestMethod.POST})
    LayuiR<User> info(String objId) {
        User info = userService.info(objId);
        return LayuiR.data(info);
    }

    @RequestMapping(value = "update", method = {RequestMethod.POST})
    void update(User user) {
        userService.update(user);
    }


}
